package org.fhm.zdte.client.service.notify;

import org.fhm.substrate.annotation.BeanInitial;
import org.fhm.substrate.annotation.Component;
import org.fhm.substrate.annotation.Setup;
import org.fhm.zdte.client.standard.INotification;
import org.fhm.zdte.client.standard.INotifier;
import org.fhm.zdte.client.standard.IObserver;
import org.fhm.zdte.common.pojo.Servlet;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * The notification manager is used to manage notification of {@link Servlet}.
 *
 * @author 谭波
 * @since 2024/3/28
 */
@Component
public class ServletNotify implements INotifier {

    private final List<IObserver> iObservers = new ArrayList<>();
    @Setup
    private Map<String, IObserver> observerMap;

    @Override
    public void registerObserver(IObserver iObserver) {
        iObservers.add(iObserver);
    }

    @Override
    public void notify(INotification notification) {
        iObservers.forEach(observer -> observer.receive(notification));
    }

    @BeanInitial
    private void beanInitial() {
        iObservers.addAll(observerMap.values());
    }

}
